package display

import "fmt"

// Bytes is the display function of []byte data
func Bytes(in []byte) {
	fmt.Println("\nBytes output is:")
	fmt.Println("=======================================================================================")
	fmt.Println("  |  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 | 0 1 2 3 4 5 6 7 8 9 A B C D E F |")
	fmt.Println("--|-------------------------------------------------|---------------------------------|")
	row := 0
	for i := 0; i < len(in); i += 16 {
		var line = fmt.Sprintf("%2d| ", row)
		for j := 0; j < 16; j++ {
			index := i + j
			if index < len(in) {
				line += fmt.Sprintf("%02x ", in[index])
			} else {
				line += "   "
			}
		}
		line += "| "
		for j := 0; j < 16; j++ {
			index := i + j
			if index < len(in) {
				if in[index] > 0x1f && in[index] < 0x7f {
					line += fmt.Sprintf("%c ", in[index])
				} else {
					line += ". "
				}
			} else {
				line += "  "
			}
		}
		line += "|"
		fmt.Println(line)
		row++
	}
	fmt.Println("=======================================================================================")
	return
}
